{php include wl_template('common/header');}
<ul class="nav nav-tabs">
    <li class="active"><a href="{php echo web_url('yellowpage/yellowpage/page_edit', array('id' => $item['id']))}">编辑黄页</a></li>
</ul>
<div class="app-content">
    <div class="app-form">
        <form action="" method="post" class="form-horizontal form form-validate">
            <div class="form-group-title">黄页信息</div>
            <div class="form-group">
                <label class="col-sm-2 control-label">排序</label>
                <div class="col-sm-9">
                    <input type="text" name="item[sort]" class="form-control" value="{$item['sort']}" placeholder="排序">
                    <div class="help-block">排序由大到小，数值越大，顺序越靠前</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="form-must">*</span>店铺名称</label>
                <div class="col-sm-9">
                    <input type="text" name="item[name]" class="form-control" value="{$item['name']}" placeholder="请输入店铺名称" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">所属用户</label>
                <div class="col-sm-9">
                    {php echo tpl_select_user('item[mid]', $item['mid'])}
                    <div class="help-block">不选择用户，则为后台添加名片,可以被用户认领。</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">关联店铺</label>
                <div class="col-sm-9">
                    <div class='input-group'>
                        <div class="input-group ">
                            <input type="text" class="form-control col-sm-9" id="namemerchant" name="" value="{$item['storename']}" style="width: 460px;" disabled>
                            <input type="hidden" value="{$item['storeid']}" id="firstid" />
                            <span class="input-group-btn">
								<button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-merchant').modal();">选择商家</button></span>
                        </div>
                        <div class="input-group " style="margin-top:.5em;">
                            <input type="hidden" value="{$item['storeid']}" name="item[storeid]" id="sidmerchant" >
                            <img src="{if empty($item['storelogo'])}../web/resource/images/nopic.jpg{else}{php echo tomedia($item['storelogo'])}{/if}" class="img-responsive img-thumbnail" width="150" id="imgmerchant" />
                            <em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除" onclick="remove_merchant(this)">×</em>
                        </div>
                    </div>
                    <div class="help-block">选择关联店铺会与平台入驻店铺关联。</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">商户LOGO</label>
                <div class="col-sm-9">
                    {php echo attachment_select('item[logo]', $item['logo'])}
                    <div class="help-block">推荐200X200，不上传则默认使用关联店铺logo</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">商户相册</label>
                <div class="col-sm-9">
                    {php echo attachment_select_multi('item[thumbs]',$item['thumbs']);}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">联系电话</label>
                <div class="col-sm-9">
                    <input type="text" name="item[mobile]" class="form-control" value="{$item['mobile']}" placeholder="请输入商户联系电话">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">微信号</label>
                <div class="col-sm-9">
                    <input type="text" name="item[wechat_number]" class="form-control" value="{$item['wechat_number']}" placeholder="请输入商户微信号">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">微信二维码</label>
                <div class="col-sm-9">
                    {php echo attachment_select('item[wechat_qrcode]', $item['wechat_qrcode'])}
                    <div class="help-block">推荐200X200</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="form-must">*</span>定位</label>
                <div class="col-sm-9">
                    {php echo tpl_select_address('item[address]','location[lng]','location[lat]',$item['address'],$item['lng'],$item['lat'])}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">介绍</label>
                <div class="col-sm-9">
                    <input type="text" name="item[desc]" class="form-control" value="{$item['desc']}" placeholder="一句话介绍你的业务">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">详情描述</label>
                <div class="col-sm-9">
                    <div class="input-group"  style="width: 100%;">
                        {php echo tpl_diy_editor_create('item[detail]', $item['detail']);}
                    </div>
                    <span class="help-block">黄页详情描述可不填，不填则不显示</span>
                </div>
            </div>
            <div class="form-group-title">其他信息</div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="form-must">*</span>所属分类</label>
                <div class="col-sm-9">
                    {php echo tpl_form_field_category_2level('category', $categorys['parents'], $categorys['childrens'], $item['one_class'], $item['two_class'])}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="form-must">*</span>套餐</label>
                <div class="col-sm-9">
                    <select name="item[meal_id]" class="form-control">
                        {loop $meals $meal}
                        <option value="{$meal['id']}" {if $item['meal_id'] == $meal['id']}selected{/if}>{$meal['name']}</option>
                        {/loop}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="form-must">*</span>套餐到期时间</label>
                <div class="col-sm-9">
                    {php echo tpl_form_field_date('item[meal_endtime]',$item['meal_endtime']);}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">浏览量</label>
                <div class="col-sm-9">
                    <input type="text" name="item[pv]" class="form-control" value="{$item['pv']}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">状态</label>
                <div class="col-sm-9">
                    <label class="radio-inline">
                        <input type="radio" name="item[status]" value="0" {if empty($item['status'])}checked{/if}>禁用
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="item[status]" value="1" {if !empty($item['status'])}checked{/if}>启用
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"></label>
                <div class="col-sm-9">
                    <input type="submit" name="submit" value="提交" class="btn btn-primary min-width" />
                    <input type="hidden" name="token" value="{$_W['token']}" />
                    <input type="hidden" name="id" value="{$item['id']}" />
                </div>
            </div>
        </form>
    </div>
    <div id="modal-module-merchant" class="modal fade" tabindex="-1">
        <div class="modal-dialog" style='width: 920px;'>
            <div class="modal-content">
                <div class="modal-header">
                    <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                    <h3>选取</h3></div>
                <div class="modal-body">
                    <div class="row">
                        <div class="input-group">
                            <input type="text" class="form-control" name="keyword" value="" id="search-kwd-merchant" placeholder="请输入商家名称，不输入任何内容搜索结果为所有商家。" />
                            <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_merchant();">搜索</button></span>
                        </div>
                    </div>
                    <div id="module-merchant" style="padding-top:5px;"></div>
                </div>
                <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
            </div>
        </div>
    </div>
</div>
<script>
    function search_merchant() {
        $("#module-merchant").html("正在搜索....")
        $.get("{php echo web_url('goodshouse/goodshouse/selectMerchant')}", {
            keyword: $.trim($('#search-kwd-merchant').val())
        }, function(dat){
            $('#module-merchant').html(dat);
        });
    }
    function remove_merchant(obj){
        $('#goodsidmerchant').val('');
        $('#namemerchant').val('');
        $('#imgmerchant').attr("src",'');
        $('#sidmerchant').val('');
    }
    function select_merchant(o) {
        var lastid = $('#sidmerchant').val();
        var fristid = $('#firstid').val();
        if (lastid != o.id) {
            $('#sidmerchant').val(o.id);
            $('#namemerchant').val(o.storename);
            $('#imgmerchant').attr("src",o.logo);
            $('#modal-module-merchant').modal('hide');
            if(fristid != o.id){
                inspect();
            }
        }else{
            $('#modal-module-merchant').modal('hide');
        }
    }
</script>
{php include wl_template('common/footer');}